package com.situ.service.impl;

import com.situ.bean.Cart;
import com.situ.bean.Product;
import com.situ.bean.User;
import com.situ.dao.CartDao;
import com.situ.dao.CartMapper;
import com.situ.service.ICartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

    @Service
public class CartService implements ICartService {
    @Autowired
    CartDao cartDao;



    @Override
    public List<Cart> getcart(User user) {
        System.out.println("查询购物车信息");
        System.out.println(cartDao.getcart(user).toString());
        return cartDao.getcart(user);
    }

    @Override
    public List<Product> getProducts(User user) {
         System.out.println("查询商品信息");
        return   cartDao.getProducts(user);
    }

    @Override
    public boolean updatecart(Cart cart) {
           System.out.println("修改购物车信息");
         return cartDao.updatecart(cart);
    }

        @Override
        public Cart getcartbypuId(Cart cart) {
          return cartDao.getcartbypuId(cart);
        }

        @Override
        public void addcart(Cart cart) {
            cartDao.addcart(cart);
        }


        @Autowired
        private CartMapper cartMapper;

        // 删除购物车中的某个商品
        public void deleteCartItem(int userid, int productid) {
            cartMapper.deleteCartItem(userid, productid);
        }

        // 清空某个用户的购物车
        public void clearCart(int userid) {
            cartMapper.clearCart(userid);
        }


    }
